/*
 * Ken Anderson, 2009
 */

#ifndef VISUALIZER_H
#define VISUALIZER_H

#ifdef WIN32
# include "SDL.h"
# include "SDL_OpenGL.h"
#else
# include <SDL/SDL.h>
# include <SDL/SDL_opengl.h>
#endif
#include "EventHandler.h"
#include "Graph.h"
#include "Search.h"
#include "Renderer.h"
#include <vector>

#define FRAME_INTERVAL	16		// Minimum time between updates (~60Hz)
#define COLOR_HEURISTIC	true
#define FONT_NAME		"../Fonts/cour.ttf"

// The Visualizer sets up the openGL rendering of a graph, heuristic, and/or search algorithm.
// Do not use the visualizer if you do not want to run algorithm timing tests.
// 
class Visualizer
{
protected:
	// These methods are used to visualize the values of the nodes on the open list.
	enum ColoringMethod { NONE, COLOR_F_VALUE, COLOR_G_VALUE, COLOR_NUM_EXPANSIONS };

	Graph * mGraph;
	Heuristic * mHeuristic;
	Search * mSearch;
	std::vector<Search*> mSearches;
	unsigned int mSearchesIndex;
	WorldState mWorldState;
	Renderer * mRenderer;
	EventHandler * mEventHandler;
	static const ColoringMethod mColoringMethod = NONE;

	void InitializeSDL();
	void InitializeDrawContext();
	void WorldStateUpdate();
	void WaitForFrameEnd();
	void GameLoop();
	void RenderFrame();
	
public:
	Visualizer ();
	virtual ~Visualizer();
	void Initialize( Graph * graph );
	void Initialize( Heuristic * heuristic );
	// Use if you only want to visualize a single search algorithm.
	void Initialize( Search * search );
	// Use if you want to view multiple searches (you may toggle between them).
	void Initialize( std::vector<Search*> searches );
	// Once you enter this loop, the only way out is to press ESC.
	void VisualizerLoop();
	void Cleanup();
};

#endif
